﻿using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using VisionRoc.Tool;

namespace VisionRoc.Core
{
    //标定结果类
    [XmlInclude(typeof(CalibrationData))]
    [XmlRoot("CalibrationData")]
    public class CalibrationData
    {
        [XmlElement("CalibType")]
        public string CalibrationDataType { get; set; }

        [XmlElement("SX")]
        public double SX { get; set; }

        [XmlElement("SY")]
        public double SY { get; set; }

        [XmlElement("Phi")]
        public double Phi { get; set; }

        [XmlElement("Theta")]
        public double Theta { get; set; }

        [XmlElement("TX")]
        public double TX { get; set; }

        [XmlElement("TY")]
        public double TY { get; set; }

        //旋转中心和半径
        [XmlElement("ImageRotatoCenterX")]
        public double ImageRotatoCenterX { get; set; }

        [XmlElement("ImageRotatoCenterY")]
        public double ImageRotatoCenterY { get; set; }

        [XmlElement("ImageRotatoRadius")]
        public double ImageRotatoRadius { get; set; }

        //平移旋转标定的关键点
        [XmlElement("ImageKeyPointX")]
        public double ImageKeyPointX { get; set; }

        [XmlElement("ImageKeyPointY")]
        public double ImageKeyPointY { get; set; }

        [XmlElement("ImageKeyPointAngle")]
        public double ImageKeyPointAngle { get; set; }

        //角度线性拟合的系数K和偏移B Y=KX+B 
        [XmlElement("AngleLinearFitFactorK")]
        public double AngleLinearFitFactorK { get; set; }

        [XmlElement("AngleLinearFitFactorB")]
        public double AngleLinearFitFactorB { get; set; }


        public override string ToString()
        {
            double Deg = MyHOperatorSet.RadToDeg(Phi);
            if (CalibrationDataType == "旋转标定")
            {
                return $"标定类型:{CalibrationDataType}{Environment.NewLine}旋转中心X:{ImageRotatoCenterX.ToString("F3")}{Environment.NewLine}旋转中心Y:{ImageRotatoCenterY.ToString("F3")}{Environment.NewLine}旋转半径R:{ImageRotatoRadius.ToString("F3")}";
            }
            else if (CalibrationDataType == "平移旋转标定")
            {
                return $"标定类型:{CalibrationDataType}{Environment.NewLine}角度偏移K:{AngleLinearFitFactorK.ToString("F3")}{Environment.NewLine}角度偏移B:{AngleLinearFitFactorB.ToString("F3")}{Environment.NewLine}缩放系数X:{SX.ToString("F3")}{Environment.NewLine}缩放系数Y:{SY.ToString("F3")}{Environment.NewLine}旋转角度:{Deg.ToString("F3")}{Environment.NewLine}斜切值:{Theta.ToString("F3")}{Environment.NewLine}平移X:{TX.ToString("F3")}{Environment.NewLine}平移Y:{TY.ToString("F3")}";
            }
            else
            {
                return $"标定类型:{CalibrationDataType}{Environment.NewLine}缩放系数X:{SX.ToString("F3")}{Environment.NewLine}缩放系数Y:{SY.ToString("F3")}{Environment.NewLine}旋转角度:{Deg.ToString("F3")}{Environment.NewLine}斜切值:{Theta.ToString("F3")}{Environment.NewLine}平移X:{TX.ToString("F3")}{Environment.NewLine}平移Y:{TY.ToString("F3")}";
            }
        }
    }
}
